EC-CUBE 2.11.4
[ class tree: EC-CUBE 2.11.4 ] [ index: EC-CUBE 2.11.4 ] [ all elements ]

Source for file SC_GraphBar.php

Documentation is available at SC_GraphBar.php

  1. <?php
  2. /*
  3.  * This file is part of EC-CUBE
  4.  *
  5.  * Copyright(c) 2000-2011 LOCKON CO.,LTD. All Rights Reserved.
  6.  *
  7.  * http://www.lockon.co.jp/
  8.  *
  9.  * This program is free software; you can redistribute it and/or
  10.  * modify it under the terms of the GNU General Public License
  11.  * as published by the Free Software Foundation; either version 2
  12.  * of the License, or (at your option) any later version.
  13.  *
  14.  * This program is distributed in the hope that it will be useful,
  15.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17.  * GNU General Public License for more details.
  18.  *
  19.  * You should have received a copy of the GNU General Public License
  20.  * along with this program; if not, write to the Free Software
  21.  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  22.  */
  23.  
  24. $ownDir = realpath(dirname(__FILE__)) . '/';
  25. require_once $ownDir . 'SC_GraphLine.php';
  26.  
  27. // 棒グラフ生成クラス
  28. class SC_GraphBar extends SC_GraphLine{
  29.     // コンストラクタ
  30.     function SC_GraphLine(
  31.         $bgw = BG_WIDTH, $bgh = BG_HEIGHT, $left = LINE_LEFT, $top = LINE_TOP,
  32.         $area_width = LINE_AREA_WIDTH, $area_height = LINE_AREA_HEIGHT) {
  33.         parent::SC_GraphLine($bgw, $bgh, $left, $top, $area_width, $area_height);
  34.     }
  35.  
  36.     // グラフの描画
  37.     function drawGraph() {
  38.         $this->drawYLine();
  39.         $this->drawXLine(true);
  40.  
  41.         // 棒グラフの描画
  42.         for($i = 0; $i < $this->line_max; $i++) {
  43.             $this->drawBar($i);
  44.         }
  45.  
  46.         // ラベルの描画
  47.         for($i = 0; $i < $this->line_max; $i++) {
  48.             $this->drawLabel($i);
  49.         }
  50.  
  51.         // 凡例の描画
  52.         $this->drawLegend();
  53.     }
  54.  
  55.     // 棒グラフの描画
  56.     function drawBar($line_no) {
  57.         $arrPointList = $this->arrPointList[$line_no];
  58.         // データ数を数える
  59.         $count = count($arrPointList);
  60.         // 半目盛りの幅を求める
  61.         $half_scale = intval($this->area_width / ($count + 1) / 2);
  62.         // 目盛りの幅を求める
  63.         $scale_width = intval($this->area_width / ($count + 1));
  64.         // 棒グラフのサイズを求める
  65.         $bar_width = intval(($scale_width - (BAR_PAD * 2)) / $this->line_max);
  66.         // 色数の取得
  67.         $c_max = count($this->arrColor);
  68.         for($i = 0; $i < $count; $i++) {
  69.             $left = $arrPointList[$i][0] - $half_scale + BAR_PAD + ($bar_width * $line_no);
  70.             $top = $arrPointList[$i][1];
  71.             $right = $left + $bar_width;
  72.             $bottom = $this->top + $this->area_height;
  73.  
  74.             // 影の描画
  75.             if($this->shade_on) {
  76.                 imagefilledrectangle($this->image, $left + 2, $top + 2, $right + 2, $bottom, $this->shade_color);
  77.             }
  78.             //imagefilledrectangle($this->image, $left, $top, $right, $bottom, $this->arrColor[($i % $c_max)]);
  79.             imagefilledrectangle($this->image, $left, $top, $right, $bottom, $this->arrColor[$line_no]);
  80.             imagerectangle($this->image, $left, $top, $right, $bottom, $this->flame_color);
  81.         }
  82.     }
  83.  
  84.     // ラベルを描画する
  85.     function drawLabel($line_no) {
  86.         $arrData = $this->arrDataList[$line_no];
  87.         $arrPointList = $this->arrPointList[$line_no];
  88.         $count = count($arrPointList);
  89.         for($i = 0; $i < $count; $i++) {
  90.             $x = $arrPointList[$i][0];
  91.             $y = $arrPointList[$i][1];
  92.             $text_width = $this->getTextWidth(number_format($arrData[$i]), FONT_SIZE);
  93.             $y_pos = $y - FONT_SIZE - 5;
  94.             $x_pos = $x - $text_width / 2;
  95.             $this->setText(FONT_SIZE, $x_pos, $y_pos, number_format($arrData[$i]));
  96.         }
  97.     }
  98.  
  99. }
  100. ?>

Documentation generated on Fri, 24 Feb 2012 14:02:35 +0900 by Seasoft